package com.example.aijiancece;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.aijiancece.database.DatabaseHelper;
import com.google.android.material.appbar.MaterialToolbar;

public class DetectionResultActivity extends AppCompatActivity {

    public static final String EXTRA_CONTENT = "content";
    public static final String EXTRA_RESULT = "result";
    public static final String EXTRA_ANALYSIS = "analysis";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detection_result);

        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        TextView tvContent = findViewById(R.id.tvContent);
        TextView tvResult = findViewById(R.id.tvResult);
        TextView tvAnalysis = findViewById(R.id.tvAnalysis);

        // 设置返回按钮点击事件
        toolbar.setNavigationOnClickListener(v -> {
            finish();
            overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        });

        // 获取传递的数据
        String content = getIntent().getStringExtra(EXTRA_CONTENT);
        String result = getIntent().getStringExtra(EXTRA_RESULT);
        String analysis = getIntent().getStringExtra(EXTRA_ANALYSIS);

        // 显示数据
        tvContent.setText(content);
        tvResult.setText(result);
        tvAnalysis.setText(analysis);

        // 保存检测历史
        DatabaseHelper.getInstance(this).addHistory(content, result, analysis);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    }
} 